<?

if ($c = stack('name')) {

	$_id_component	= $DATA['components'][$c]['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value
	
	$_lang = context('lang');

	$_crit = "id_data=$_id_data AND id_parent=$_id_component";


	$s = array_extend( array('path' => 'article', 'w' => 128, 'h' => 96, 'param' => 'id'), $DATA['components'][$c]['settings']);

	$s['path'] = createdir(FP_UPLOAD_PATH.$s['path'].'/');
	$s['h'] = (int)$s['h'];
	$s['w'] = (int)$s['w'];

	$a = param($s['param']);

	if ( $temp = datafetch('db_item', tb('data'), "$_crit AND id=$a")) {
		
		$_meta = datafetch_array('loadmeta', $_id_meta, 
			array('parent' => $a, 'assoc' => $_lang, 'getclob' => true));
		
		$temp = array_merge($temp, $_meta);
		
		$temp['date'] = format_simple_date($temp['date_create']);
		$DATA['components'][$c]['data'] = $temp;

		// fix crumbs
		
		addCrumb(array(
			'name' => $temp['title'],
			'path' => _transformURL($CURRENT->url, array('remove_params' => 'all', 'add_param' => "$s[param]:$a"))
		));
		
	} else {
		
		header("HTTP/1.0 404 Not Found\n");
		header("Location: "._transformURL($CURRENT->url, array('remove_param' => $s['param'])));
	}

	unstack();
}